package com.mzm.domain;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.mzm.api.ProductType;

@Entity(name = "ProductInfo")
@Table(name = "PRODUCT_INFO")
public class ProductInfo extends BaseEntity {

	@Column(name = "PRODUCT_NAME")
	private String productName;

	@Enumerated(EnumType.STRING)
	@Column(name = "PRODUCT_TYPE")
	private ProductType productType;

	@OneToMany(mappedBy = "productInfo", orphanRemoval = true)
	@Cascade({ CascadeType.ALL })
	private Set<ProductImageInfo> imageInfos;

	@ManyToOne
	@Cascade({ CascadeType.REFRESH })
	@JoinColumn(name = "CATEGORY_ID")
	private Category category;

	public ProductInfo() {
	}

	public ProductInfo(String productName, ProductType productType) {
		this.productName = productName;
		this.productType = productType;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public ProductType getProductType() {
		return productType;
	}

	public void setProductType(ProductType productType) {
		this.productType = productType;
	}

	public Set<ProductImageInfo> getImageInfos() {
		return imageInfos;
	}

	public void setImageInfos(Set<ProductImageInfo> imageInfos) {
		this.imageInfos = imageInfos;
		for (ProductImageInfo productImageInfo : imageInfos) {
			productImageInfo.setProductInfo(this);
		}
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

}
